from django.db import models

# Create your models here.
# 定义会员模型
class Users(models.Model):
    nikename = models.CharField(max_length=20,null=True)
    password = models.CharField(max_length=77)
    # phone = models.CharField(max_length=11,unique=True)
    phone = models.CharField(max_length=11)
    email = models.CharField(max_length=100)
    age = models.IntegerField(null=True)
    pic_url = models.CharField(max_length=100)
    SEX_CHOICES = (
        (0, '女'),
        (1, '男'),
    )
    sex = models.CharField(max_length=1,null=True,choices=SEX_CHOICES)
    # 0 正常  1禁用  2 删除 ....
    status = models.IntegerField(default=0)
    addtime = models.DateTimeField(auto_now_add=True)

# 商品分类模型
class Cates(models.Model):
    name = models.CharField(max_length=20)
    description = models.CharField(max_length=255)
    pid = models.IntegerField()
    path = models.CharField(max_length=50)
    thumbnail = models.CharField(max_length=255)

# 商品模型
class Goods(models.Model):
    # id 所属分类,商品名,图片,添加时间,销量

    cateid = models.ForeignKey(to="Cates", to_field="id")
    goodsname = models.CharField(max_length=50)
    title = models.CharField(max_length=255)
    price = models.FloatField()
    oldprice=models.FloatField()
    goodsnum = models.IntegerField()
    pic_url = models.CharField(max_length=255)
    pics = models.TextField()
    description = models.TextField()
    goodsinfo = models.TextField()
    ordernum =  models.IntegerField(default=0)
    clicknum = models.IntegerField(default=0)
    # 0 新品,1热卖,2推荐,3下架
    status = models.IntegerField(default=0)
    addtime = models.DateTimeField(auto_now_add=True)

# 购物车 模型
class Cart(models.Model):
    # id  用户 uid   商品 goodsid 数量 num
    uid = models.ForeignKey(to="Users", to_field="id")
    goodsid = models.ForeignKey(to="Goods", to_field="id")
    num = models.IntegerField()

# 收货人信息表
class ConsigneeInfo(models.Model):
    #收货人
    cname = models.CharField(max_length=20)
    #收货人手机号
    tel = models.CharField(max_length=11)
    #省
    province = models.CharField(max_length=50)
    #市
    city = models.CharField(max_length=50)
    #区
    district = models.CharField(max_length=50)
    #详细地址
    address = models.CharField(max_length=250)
    #邮政编码
    postcode = models.CharField(max_length=11)
    #地址标签
    alias = models.CharField(max_length=50)
    #用户id
    uid = models.ForeignKey(to="Users", to_field="id")
    #是否是默认地址(1默认地址)
    status = models.IntegerField(default=0)

# 订单
class Order(models.Model):
    uid = models.ForeignKey(to="Users", to_field="id")
    username = models.CharField(max_length=20)
    phone = models.CharField(max_length=11)
    address = models.ForeignKey(to="ConsigneeInfo", to_field="id")
    totalprice = models.FloatField()
    # 0 未支付, 1已支付, 2已发货  3已收货  4已评价  5取消 ...
    status = models.IntegerField(default=0)
    #送货时间 #0不限时间 1周末 2周一到周五
    sofort = models.IntegerField(default=0)
    paytype = models.IntegerField(default=0)
    addtime = models.DateTimeField(auto_now_add=True)
    paytime = models.DateTimeField(null=True)


# 订单详情
class OrderInfo(models.Model):
    orderid = models.ForeignKey(to="Order", to_field="id")
    goodsid = models.ForeignKey(to="Goods", to_field="id")
    num = models.IntegerField()


